from PyQt5 import QtCore, QtGui, QtPrintSupport, QtWidgets
from datetime import datetime


app = QtWidgets.QApplication([])

class PDF:
    def __init__(self):
        self.doc = QtGui.QTextDocument()
        self.printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.PrinterResolution)
        self.printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
        self.printer.setPaperSize(QtPrintSupport.QPrinter.A4)
        self.printer.setOrientation(QtPrintSupport.QPrinter.Landscape)
        self.html = """<html>
                        <head>
                            <style>
                                p{
                                    font-size: 12px;
                                    font-weight: 200;
                                    color: black;
                                }
                                .title{
                                    font-size: 15px;
                                    text-align: center;
                                    font-weight: 700;
                                }
                        
                        
                                .info{
                                    margin: 20px;
                                }
                        
                                table {
                                    margin: 20px;
                                    font-size: 10px;
                                    border-collapse:collapse;
                                }

                                td {
                                    border: 1px solid black;
                                    text-align: center;
                                    padding: 15px;
                                }
                        </style>
                        </head>
                    """
        self.title = "BEARINGS SU"
        self.info = datetime.now()
        self.html += f"""
                    <p class='title'>{self.title}</p>
                    <p class='info'>{self.info}</p>
                    <table>
                    """
    def save(self, filename="test.pdf"):
        self.html+="</table>"        
        self.printer.setOutputFileName(filename)
        self.doc.setHtml(self.html)
        self.doc.setPageSize(QtCore.QSizeF(self.printer.pageRect().size()))
        self.doc.print_(self.printer)


    def add_begining_row_to_table(self, data: dict[str, str]):
        self.html += "<tr>"
        for key, val in data.items():
            self.html += f"<td>{key}</td>\
                    <td>{val}</td>"
        self.html += "</tr>"
    
    


data_1_row: dict = {
    "ENGINE": "XXX",
    "FUEL": "XXX",
    "MAX CIL PRESSURE": "XXX",
    "APPLICATION":"XXX"
}

data_2_row: dict = {
    "VOL (L)": "XXX",
    "TYPE" : "XXX",
    "OIL SUPPLY PRESSURE (MPa)" : "XXX",
    "TURBO" : "XXX"
}

data_3_row: dict ={
    "SPEED (rpm)" : "xxx",
    "BORE (mm)" : "xxx",
} 

data_4_row: dict = {
    "FIRING" : "xxx"
}

# pdf = PDF()
# pdf.add_row_to_table(data)
# pdf.add_row_to_table(data)
# pdf.add_row_to_table(data)
# pdf.save()